{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/jump_img/index')}">图片管理</a></li>
            <li class="layui-this">添加图片</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/jump_img/save')}" method="post">
                    <div class="layui-form-item" id="leixing1">
                        <label class="layui-form-label">所属分类</label>
                        <div class="layui-input-block">
                            <select name="pid" lay-verify="required" lay-filter="one">
                                <option value="">请选择分类</option>
                                {foreach name="jumpcategory_level_list" item="vo"}
                                <option value="{$vo.id}">{eq name="vo.level" value="1"}{$vo.name}{/eq} </option>
                                {/foreach}
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" value="" required  lay-verify="required" placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图片</label>
                        <div class="layui-input-block">
                            <input type="text" name="thumb" value="" class="layui-input layui-input-inline" id="thumb">
                            <input type="file" name="file" class="layui-upload-file">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图集</label>
                        <div class="layui-input-block">
                            <button type="button" id="upload-photo-btn" class="layui-btn">上传图集</button>
                            <div id="photo-container"></div>
                        </div>
                    </div>
                    <div class="layui-form-item" style="display:none;">
                        <label class="layui-form-label">内容</label>
                        <div class="layui-input-block">
                            <textarea name="content" placeholder="" class="layui-textarea" id="content"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="*">保存</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script src="__JS__/kindeditor/kindeditor.config.js"></script>
<script src="__JS__/kindeditor/kindeditor-all-min.js"></script>
{/block}
{block name="script"}
<script>
    $(document).ready(function () {
        var _kindEditor;
        KindEditor.ready(function(K) {
            _kindEditor = K.create('#content', KindEditorOptions);

            K('#upload-photo-btn').click(function () {
                var photo_list_item = '';
                _kindEditor.loadPlugin('multiimage', function() {
                    _kindEditor.plugin.multiImageDialog({
                        showRemote : false,
                        imageUrl : K('#photo').val(),
                        clickFn : function(data) {
                            $.each(data, function (index, item) {
                                photo_list_item += '<div class="photo-list"><input type="text" name="photo[]" value="' + item.url + '" class="layui-input layui-input-inline">';
                                photo_list_item += '<button type="button" class="layui-btn layui-btn-danger remove-photo-btn">移除</button></div>'
                            });
                            $('#photo-container').append(photo_list_item);
                            _kindEditor.hideDialog();
                        }
                    });
                });
            });
        });

        $('#photo-container').on('click', '.remove-photo-btn', function () {
            $(this).parent('.photo-list').remove();
        });
    });
</script>

<script>
    layui.use('form', function(){
    var form = layui.form();
        form.on('select(one)', function(data){
            // console.log(data.value); //得到被选中的值
            $('#leixing2').remove();
            $.get('/admin/wenan/getChildMenu',{id:data.value},function(res){
                if(res.length > 0){
                    var options = '';
                    for(var i = 0;i < res.length;i++){
                        options += '<option value="'+res[i].id+'">'+res[i].name+'</option>';
                    }

                    $('#leixing1').after('<div class="layui-form-item" id="leixing2"><label class="layui-form-label">所属栏目</label><div class="layui-input-block"><select name="pid" lay-verify="required" lay-filter="two"><option value="">请选择栏目</option>'+options+'</select></div></div>');
                    form.render('select');
                }
            });
        });

        form.on('select(two)', function(data){
            // console.log(data.value); //得到被选中的值
            $('#leixing3').remove();
            $.get('/admin/wenan/getChildMenu',{id:data.value},function(res){
                if(res.length > 0){
                    var options = '';
                    for(var i = 0;i < res.length;i++){
                        options += '<option value="'+res[i].id+'">'+res[i].name+'</option>';
                    }

                    $('#leixing2').after('<div class="layui-form-item" id="leixing3"><label class="layui-form-label">所属子类</label><div class="layui-input-block"><select name="pid" lay-verify="required" lay-filter="thr"><option value="">请选择子类</option>'+options+'</select></div></div>');
                    form.render('select');
                }
            });
        });
    //各种基于事件的操作，下面会有进一步介绍
    });
</script>
{/block}